/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
var levelOrder = function(root) {
    // 层序是队列
const q=[root],res=[]
if(!root)return res
while(q.length){
    let len=q.length,temp=[]
    for(let i=1;i<=len;i++){
        let node=q.shift()
        temp.push(node.val)
        
        node.left&&q.push(node.left)
        node.right&&q.push(node.right)
    }
    res.push(temp)
}
return res
};